//
//  GTFlutterConfig.swift
//  Runner
//
//  Created by Shper on 2023/5/6.
//

import Foundation
import Flutter
import lib_core

public class GTFlutterInitConfig: GTFlutterGlobalConfigBuilder {
    
    // 是否预热 Flutter 引擎
    public var preheatEngine: Bool = false
    // 引擎插件注册
    public var onPluginRegistrant: ((_ engine: FlutterEngine, _ route: String) -> Void) = { _,_  in }
    // Flutter View Controller 创建后回调
    public var onViewControllerCreated: ((GTFlutterViewController, String, [String: Any]?) -> Void)?
    
    public var onStartedPageListChanged: (([String]) -> Void)?

    public override init() {
        super.init()
    }
    
    func toJson(extendDic: [String: Any], customDarkMode: Bool? = nil) -> String {
        var dic: [String: Any] = super.toDic(customDarkMode: customDarkMode)
        
        // 合并字典
        if (!extendDic.isEmpty) {
            dic.merge(extendDic) { _, second in
                return second
            }
        }
        // 转成 JsonString
        return GTFlutterUitls.convertDictionaryToString(dic)
    }
    
}
